import type { MerakXFormItemProps } from "@/components/MerakXFormItem";

import I18n from "@/languages/index";

import useDateFormat from "@/hooks/useDateFormat";

import dayjs from "dayjs";

import customParseFormat from 'dayjs/plugin/customParseFormat';

dayjs.extend(customParseFormat)

const t = I18n.global.t;

const { format, renderFormat } = useDateFormat();

export const enum ComponentKeys {
  user = "user",
  newsletter = "newsletter",
  education = "education",
  job = "job",
  contract = "contract",
  annex = "annex"
}

export const renderAge = (date?: string | number | Date | dayjs.Dayjs) => dayjs().diff(dayjs(date, format), "years");

export const renderTwelve = (date?: string | number | Date | dayjs.Dayjs) => {
  const arr = ["monkey", "chicken", "dog", "pig", "mouse", "cattle", "tiger", "rabbit", "dragon", "snake", "horse", "sheep"];
  const year = dayjs(date, format).year();
  return arr[year % 12];
};

export const renderConstellation = (date?: string | number | Date | dayjs.Dayjs) => {
  const arr = [
    "aquarius",
    "pisces",
    "aries",
    "taurus",
    "gemini",
    "cancer",
    "leo",
    "virgo",
    "libra",
    "scorpio",
    "sagittarius",
    "capricorn"
  ];
  const days = [21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22];
  const day = dayjs(date, format).date();
  const month = dayjs(date, format).month();
  if (month === 0 && day <= 20) {
    return { key: 12, value: arr[11] };
  }
  if (day < days[month]) {
    return { key: month, value: arr[month - 1] };
  }
  return { key: month + 1, value: arr[month] };
};

export const userItems: MerakXFormItemProps[] = [
  { prop: "employee_name", label: "姓名", type: "input" },
  { prop: "employee_alias", label: "别名", type: "input" },
  { prop: "nationality", label: "国籍", type: "select" },
  {
    prop: "sex",
    label: "性别",
    type: "radio",
    options: [
      { value: 0, label: t("staff_list.woman") },
      { value: 1, label: t("staff_list.man") }
    ]
  },
  {
    prop: "birthday",
    label: "出生日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  { prop: "age", label: "年龄", type: "input", props: { readonly: true } },
  { prop: "twelve", label: "生肖", type: "input", props: { readonly: true } },
  { prop: "constellation", label: "星座", type: "select", props: { disabled: true, placeholder: "", suffixIcon: "" } },
  { prop: "nation", label: "民族", type: "input" },
  { prop: "politics_status", label: "政治面貌", type: "select" },
  // { prop: "id_type", label: "证件类型", type: "select" },
  { prop: "id_no", label: "身份证号码", type: "input" },
  { prop: "passport_no", label: "护照号码", type: "input" },
  { prop: "native_place_city", label: "籍贯", type: "select" },
  {
    prop: "household_registration_type",
    label: "户口性质",
    type: "radio",
    options: [
      { value: 0, label: t("staff_list.urban_registration") },
      { value: 1, label: t("staff_list.rural_household_registration") }
    ]
  },
  { prop: "permanent_residence_city", label: "户籍", type: "select" },
  { prop: "permanent_residence_address", label: "户籍地址", type: "input" },
  { prop: "current_address", label: "现居住地", type: "input" },
  {
    prop: "marriage",
    label: "婚姻情况",
    type: "radio",
    options: [
      { value: 0, label: t("staff_list.unmarried") },
      { value: 1, label: t("staff_list.married") }
    ]
  },
  {
    prop: "fertility",
    label: "生育情况",
    type: "radio",
    options: [
      { value: 0, label: t("staff_list.not_fertile") },
      { value: 1, label: t("staff_list.already_bred") }
    ]
  },
  { prop: "blood_type", label: "血型", type: "select" },
  { prop: "strong_point", label: "特长", type: "input" }
];

export const newsletterItems: MerakXFormItemProps[] = [
  { prop: "mobile", label: "手机号码", required: true, render: "custom_mobile" },
  { prop: "phone", label: "工作电话", type: "input", props: { numberType: {} } },
  { prop: "wechat", label: "微信号", type: "input" },
  { prop: "personal_email", label: "个人邮箱", type: "input" },
  { prop: "company_email", label: "工作邮箱", type: "input" },
  { prop: "emergency_contact_name", label: "紧急联系人姓名", type: "input" },
  { prop: "emergency_contact_relationship", label: "紧急联系人关系", type: "input" },
  { prop: "emergency_contact_mobile", label: "紧急联系人电话", type: "input", props: { numberType: {} } },
  { prop: "emergency_contact_address", label: "紧急联系人地址", type: "input" }
];

export const educationItems: MerakXFormItemProps[] = [
  { prop: "education", label: "最高学历", type: "select" },
  { prop: "degree_type", label: "最高学位", type: "select" },
  { prop: "graduate_school", label: "毕业院校", type: "input" },
  { prop: "graduate_major", label: "毕业专业", type: "input" },
  {
    prop: "education_start",
    label: "教育开始时间",
    type: "datePicker",
    props: {
      type: "month",
      format: renderFormat("YYYY-MM"),
      valueFormat: "YYYY-MM"
    }
  },
  {
    prop: "education_end",
    label: "教育结束时间",
    type: "datePicker",
    props: {
      type: "month",
      format: renderFormat("YYYY-MM"),
      valueFormat: "YYYY-MM"
    }
  },
  { prop: "study_model", label: "学习形式", type: "select" }
];

export const jobItems: MerakXFormItemProps[] = [
  { prop: "job_no", label: "OA工号", type: "input" },
  { prop: "username", label: "账号/登录名", type: "input" },
  { prop: "password", label: "密码", type: "input", props: { type: "password", showPassword: true } },
  { prop: "org_group", label: "公司/部门/岗位", type: "treeSelect", props: { multiple: true } },
  { prop: "job_nature", label: "工作性质", type: "select" },
  { prop: "status", label: "员工状态", type: "select" },
  { prop: "office_location_id", label: "工作城市", type: "select" },
  { prop: "visa_type", label: "签证类型", type: "input" },
  { prop: "visa_number", label: "签证号", type: "input" },
  { prop: "visa_entity", label: "签证主体单位", type: "input" },
  { prop: "visa_expiration_date", label: "签证有效期终止时间", type: "datePicker", props: { format, valueFormat: "YYYY-MM-DD" } },
  { prop: "direct_superiors", label: "直接上级", type: "select" },
  {
    prop: "hiredate",
    label: "入职日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  { prop: "probation", label: "试用期", type: "select" },
  {
    prop: "confirmation_date",
    label: "转正日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  { prop: "company_seniority", label: "司龄", type: "input", props: { readonly: true } },
  {
    prop: "first_job_date",
    label: "首次参加工作时间",
    type: "datePicker",
    props: {
      type: "month",
      format: renderFormat("YYYY-MM"),
      valueFormat: "YYYY-MM"
    }
  },
  { prop: "seniority", label: "工龄", type: "input", props: { numberType: {} } },
  { prop: "pay_card_no", label: "工资卡卡号", type: "input" },
  { prop: "pay_card_bank_name", label: "工资卡银行名称", type: "select" },
  { prop: "pay_card_bank_fullname", label: "工资卡开户行", type: "input" },
  { prop: "social_security_city", label: "社保缴纳地", type: "select" },
  {
    prop: "left_date",
    label: "离职日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  { prop: "left_reason", label: "离职原因", type: "input" }
];

export const contractItems: MerakXFormItemProps[] = [
  { prop: "contract_type", label: "合同类型", type: "select" },
  { prop: "contract_company_id", label: "合同签署公司", type: "select" },
  { prop: "contract_period", label: "合同期限", type: "input", props: { numberType: { decimal: 1 } } },
  { prop: "contract_status", label: "合同状态", type: "select" },
  {
    prop: "contract_start",
    label: "合同开始日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  {
    prop: "contract_end",
    label: "合同结束日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  },
  {
    prop: "contract_date",
    label: "合同签订日期",
    type: "datePicker",
    props: { format, valueFormat: "YYYY-MM-DD" }
  }
];

export const vacationItems: MerakXFormItemProps[] = [
  { prop: "paid_annual_leave", label: "带薪年假标准", type: "input", props: { numberType: {} } },
  { prop: "paid_sick_leave", label: "带薪病假标准", type: "input", props: { numberType: {} } }
];

export const vacationRemainItems: MerakXFormItemProps[] = [
  { prop: "remaining_annual_leave", label: "剩余年假", type: "input", readonly: true },
  { prop: "remaining_sick_leave", label: "剩余病假", type: "input", readonly: true }
];
